package edu.winona.csclub.testing.core;

import java.util.List;

public class Test {
	
	private List<Value> variables;
	private Command command;
	
	/**
	 * @param variables
	 */
	public Test(Command command, List<Value> variables) {
		super();
		this.variables = variables;
		this.command = command;
	}

	/**
	 * returns the value assigned to this Test, or else
	 * it will return null if none exists
	 * @param id
	 * @return
	 */
	public String getValueForVariableWithId(String id){
		for( Value v : variables ){
			if(v.getVariable().getId().equals(id))
				return v.getValue();
		}
		return null;
	}

	/**
	 * @return the variables
	 */
	public List<Value> getVariables() {
		return variables;
	}

	/**
	 * @param variables the variables to set
	 */
	public void setVariables(List<Value> variables) {
		this.variables = variables;
	}

	/**
	 * @return the command
	 */
	public Command getCommand() {
		return command;
	}

	/**
	 * @param command the command to set
	 */
	public void setCommand(Command command) {
		this.command = command;
	}
	
	public String toString(){
		String ret = command.getValue();
		for( Value v : variables ){
			String id = v.getVariable().getId();
			int ind = ret.indexOf(id);
			String pref = ret.substring(0,ind);
			String post = ret.substring(ind+id.length());
			ret=pref+v.getValue()+post;
		}
		return ret;
	}
}
